package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_Weather;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1ChangeWeather implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1ChangeWeather.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1ChangeWeather();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      if (pc == null) {
        _log.warn("系统命令执行: " + cmdName + " " + arg + " 游戏天气控制。");
        _log.info("说明: 0 终止气候。");
        _log.info("说明: 1~3 雪控制。");
        _log.info("说明: 17~19 雨控制");
      } 
      StringTokenizer tok = new StringTokenizer(arg);
      int weather = Integer.parseInt(tok.nextToken());
      World.get().setWeather(weather);
      World.get().broadcastPacketToAll((ServerBasePacket)new S_Weather(weather));
    } catch (Exception e) {
      if (pc == null) {
        _log.error("错误的命令格式: " + getClass().getSimpleName());
      } else {
        _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
      } 
    } 
  }
}
